package Reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Class cla=Class.forName("Reflect.Person");
        Object obj=cla.newInstance();


        Method method=cla.getMethod("sayHello");
        method.invoke(obj);

        Method method1=cla.getMethod("getName");
        Object result=method1.invoke(obj);
        System.out.println(result);

        Scanner sc=new Scanner(System.in);
        System.out.println("请输入类");
        Class cla1=Class.forName(sc.nextLine());
        Object obj1=cla1.newInstance();
        System.out.println("请输入方法");
        Method method2=cla1.getMethod(sc.nextLine());
        Object result1=method2.invoke(obj1);
        System.out.println(result1);
    }
}